package com.lzzy.service.impl;


import com.lzzy.dao.FriendsRepository;
import com.lzzy.model.domain.Friends;
import com.lzzy.service.IFriendsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class FriendsServiceImpl implements IFriendsService {

    @Autowired
    private FriendsRepository friendsRepository;

    //返回所有友链
    @Override
    public List<Friends> findAll() {
        return friendsRepository.findAll();
    }

    //使用jpa自带的save，添加一个友链

    public void addFriend(String friendsname, String email,String link){
        //生成一个friends对象
        Friends friends = new Friends();
        //注入名字
        friends.setFriendsname(friendsname);
        //注入邮箱
        friends.setEmail(email);
        //注入友链
        friends.setLink(link);
        //注入时间
        friends.setCreated(new Date());

        friendsRepository.save(friends);
    }
}
